package com.xry.service.impl;

import com.xry.annotation.LogMethod;
import com.xry.bean.Product;
import com.xry.mapper.ProductDao;
import com.xry.service.ProductService;
import com.xry.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductDao productDao;
    @Override
    @LogMethod(serviceName = "增加产品信息")
    public Product add(Product product) {
        //新增数据
        productDao.add(product);
        //通过主键查询数据库中的数据
        Product result = productDao.one(product.getId());
        return result;
    }

    @Override
    @LogMethod(serviceName = "增加产品信息")
    public int del(Integer id) {
        return productDao.del(id);
    }

    @Override
    @LogMethod(serviceName = "修改产品信息")
    public Product edit(Product product) {
        productDao.edit(product);
        Product result=productDao.one(product.getId());
        return result;
    }

    @Override
    public List<Product> all(Product product) {
        return productDao.all( product);
    }

    @Override
    public Product one(Integer id) {
        return productDao.one(id);
    }

    @Override
    public void page(Page page,Product product){
        int count=productDao.pageCount(product);
        Object data=productDao.page(page,product);
        page.setCount(count);
        page.setData(data);
    }

    @Override
    public List<Map<String, Integer>> countBrand() {
        return productDao.countBrand();
    }

    @Override
    public List<Map<String, Integer>> countCategory() {
        return productDao.countCategory();
    }
}
